home *** CD-ROM | disk | FTP | other *** search
/ Your Web Site Creator / Your Web Site Creator.iso / WebSite / data1.cab / Program_Executable_Files / Classes / SPPANE2.CLA (.txt) < prev    next >
Encoding:
Java Class File  |  1999-01-13  |  5.2 KB  |  254 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Button;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Event;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.Panel;
  12. import java.awt.Rectangle;
  13. import java.awt.image.ImageObserver;
  14.  
  15. public class SPPanel2 extends Panel {
  16.    AudioClip theAudioClip;
  17.    boolean loopAudioClip;
  18.    boolean autoPlay = false;
  19.    boolean showButtons = false;
  20.    Button playButton;
  21.    Button stopButton;
  22.    String playLabel;
  23.    String stopLabel;
  24.    Color bkColor;
  25.    Image bkImage;
  26.    Image osImage;
  27.    Graphics osg;
  28.    // $FF: renamed from: fm java.awt.FontMetrics
  29.    FontMetrics field_0;
  30.    int fontHeight;
  31.    int playX;
  32.    int playY;
  33.    int playWidth;
  34.    int playHeight;
  35.    int stopX;
  36.    int stopY;
  37.    int stopWidth;
  38.    int stopHeight;
  39.    Rectangle playRect;
  40.    Rectangle stopRect;
  41.    boolean drawPlayRect = false;
  42.    boolean drawStopRect = false;
  43.    boolean pressPlay = false;
  44.    boolean pressStop = false;
  45.  
  46.    public SPPanel2(Applet var1, int var2) {
  47.       this.GetParameters(var1, var2);
  48.       if (this.showButtons) {
  49.          this.playButton = new Button(this.playLabel);
  50.          this.stopButton = new Button(this.stopLabel);
  51.       }
  52.  
  53.       this.playRect = new Rectangle();
  54.       this.stopRect = new Rectangle();
  55.    }
  56.  
  57.    void GetParameters(Applet var1, int var2) {
  58.       String var3 = var1.getParameter("spSound" + var2);
  59.       if (var3 != null) {
  60.          this.theAudioClip = var1.getAudioClip(var1.getCodeBase(), var3);
  61.       }
  62.  
  63.       var3 = var1.getParameter("spLoopSound" + var2);
  64.       this.loopAudioClip = AppletParam2.GetBoolean(var3, false);
  65.       var3 = var1.getParameter("spAutoPlay" + var2);
  66.       this.autoPlay = AppletParam2.GetBoolean(var3, false);
  67.       var3 = var1.getParameter("spShowButtons" + var2);
  68.       this.showButtons = AppletParam2.GetBoolean(var3, false);
  69.       var3 = var1.getParameter("spPlayLabel" + var2);
  70.       this.playLabel = AppletParam2.GetString(var3, "Play");
  71.       var3 = var1.getParameter("spStopLabel" + var2);
  72.       this.stopLabel = AppletParam2.GetString(var3, "Stop");
  73.       var3 = var1.getParameter("spBkColor" + var2);
  74.       this.bkColor = AppletParam2.GetColor(var3, (Color)null);
  75.       if (this.bkColor != null) {
  76.          ((Component)this).setBackground(this.bkColor);
  77.       }
  78.  
  79.       var3 = var1.getParameter("spBkImage" + var2);
  80.       this.bkImage = AppletParam2.GetImage(var1, var3);
  81.    }
  82.  
  83.    public boolean mouseMove(Event var1, int var2, int var3) {
  84.       boolean var4 = this.playRect.inside(var2, var3);
  85.       boolean var5 = this.stopRect.inside(var2, var3);
  86.       if (this.drawPlayRect != var4) {
  87.          this.drawPlayRect = var4;
  88.          ((Component)this).repaint();
  89.       }
  90.  
  91.       if (this.drawStopRect != var5) {
  92.          this.drawStopRect = var5;
  93.          ((Component)this).repaint();
  94.       }
  95.  
  96.       return true;
  97.    }
  98.  
  99.    public boolean mouseUp(Event var1, int var2, int var3) {
  100.       this.pressPlay = false;
  101.       this.pressStop = false;
  102.       ((Component)this).repaint();
  103.       return true;
  104.    }
  105.  
  106.    public boolean mouseDown(Event var1, int var2, int var3) {
  107.       if (this.playRect.inside(var2, var3)) {
  108.          this.pressPlay = true;
  109.          this.pressStop = false;
  110.          ((Component)this).repaint();
  111.          if (this.theAudioClip != null) {
  112.             if (this.loopAudioClip) {
  113.                this.theAudioClip.loop();
  114.             } else {
  115.                this.theAudioClip.play();
  116.             }
  117.          }
  118.       }
  119.  
  120.       if (this.stopRect.inside(var2, var3)) {
  121.          this.pressPlay = false;
  122.          this.pressStop = true;
  123.          ((Component)this).repaint();
  124.          if (this.theAudioClip != null) {
  125.             this.theAudioClip.stop();
  126.          }
  127.       }
  128.  
  129.       return true;
  130.    }
  131.  
  132.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  133.       super.reshape(var1, var2, var3, var4);
  134.       this.osImage = null;
  135.       this.osg = null;
  136.    }
  137.  
  138.    public Dimension minimumSize() {
  139.       return new Dimension(10, 10);
  140.    }
  141.  
  142.    public Dimension preferredSize() {
  143.       return new Dimension(10, 10);
  144.    }
  145.  
  146.    public void update(Graphics var1) {
  147.       this.paint(var1);
  148.    }
  149.  
  150.    public void paint(Graphics var1) {
  151.       if (this.osImage == null) {
  152.          this.osImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  153.          this.osg = this.osImage.getGraphics();
  154.       }
  155.  
  156.       this.osg.setColor(((Component)this).getBackground());
  157.       this.osg.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  158.       if (this.bkImage != null) {
  159.          int var2 = this.bkImage.getWidth(this);
  160.          int var3 = this.bkImage.getHeight(this);
  161.          int var4 = ((Component)this).size().width / var2;
  162.          int var5 = ((Component)this).size().height / var3;
  163.          ++var4;
  164.          ++var5;
  165.  
  166.          for(int var6 = 0; var6 < var5; ++var6) {
  167.             for(int var7 = 0; var7 < var4; ++var7) {
  168.                this.osg.drawImage(this.bkImage, var7 * var2, var6 * var3, this);
  169.             }
  170.          }
  171.       }
  172.  
  173.       if (this.showButtons) {
  174.          this.field_0 = ((Component)this).getFontMetrics(((Component)this).getFont());
  175.          this.playWidth = this.field_0.stringWidth(this.playLabel) + 8;
  176.          this.stopWidth = this.field_0.stringWidth(this.stopLabel) + 8;
  177.          this.playHeight = this.stopHeight = this.field_0.getHeight() + 8;
  178.          int var8 = ((Component)this).size().width / 2 - (this.playWidth + this.stopWidth + 10) / 2;
  179.          int var9 = ((Component)this).size().height / 2 - this.playHeight / 2;
  180.          this.playX = var8;
  181.          this.playY = var9;
  182.          this.stopX = this.playX + this.playWidth + 10;
  183.          this.stopY = var9;
  184.          this.playRect.reshape(this.playX, this.playY, this.playWidth, this.playHeight);
  185.          this.stopRect.reshape(this.stopX, this.stopY, this.stopWidth, this.stopHeight);
  186.          if (this.drawPlayRect) {
  187.             if (this.pressPlay) {
  188.                this.osg.setColor(Color.black);
  189.             } else {
  190.                this.osg.setColor(Color.white);
  191.             }
  192.  
  193.             this.osg.drawLine(this.playX, this.playY, this.playX + this.playWidth - 1, this.playY);
  194.             this.osg.drawLine(this.playX, this.playY, this.playX, this.playY + this.playHeight - 1);
  195.             if (this.pressPlay) {
  196.                this.osg.setColor(Color.white);
  197.             } else {
  198.                this.osg.setColor(Color.black);
  199.             }
  200.  
  201.             this.osg.drawLine(this.playX, this.playY + this.playHeight - 1, this.playX + this.playWidth - 1, this.playY + this.playHeight - 1);
  202.             this.osg.drawLine(this.playX + this.playWidth - 1, this.playY, this.playX + this.playWidth - 1, this.playY + this.playHeight - 1);
  203.          }
  204.  
  205.          this.osg.setColor(Color.black);
  206.          this.osg.drawString(this.playLabel, this.playX + 4, this.playY + this.playHeight - this.field_0.getDescent() - 4);
  207.          if (this.drawStopRect) {
  208.             if (this.pressStop) {
  209.                this.osg.setColor(Color.black);
  210.             } else {
  211.                this.osg.setColor(Color.white);
  212.             }
  213.  
  214.             this.osg.drawLine(this.stopX, this.stopY, this.stopX + this.stopWidth - 1, this.stopY);
  215.             this.osg.drawLine(this.stopX, this.stopY, this.stopX, this.stopY + this.stopHeight - 1);
  216.             if (this.pressStop) {
  217.                this.osg.setColor(Color.white);
  218.             } else {
  219.                this.osg.setColor(Color.black);
  220.             }
  221.  
  222.             this.osg.drawLine(this.stopX, this.stopY + this.stopHeight - 1, this.stopX + this.stopWidth - 1, this.stopY + this.stopHeight - 1);
  223.             this.osg.drawLine(this.stopX + this.stopWidth - 1, this.stopY, this.stopX + this.stopWidth - 1, this.stopY + this.stopHeight - 1);
  224.          }
  225.  
  226.          this.osg.setColor(Color.black);
  227.          this.osg.drawString(this.stopLabel, this.stopX + 4, this.stopY + this.stopHeight - this.field_0.getDescent() - 4);
  228.       }
  229.  
  230.       var1.drawImage(this.osImage, 0, 0, (ImageObserver)null);
  231.    }
  232.  
  233.    public void Start() {
  234.       if (this.theAudioClip != null) {
  235.          if (this.loopAudioClip) {
  236.             this.theAudioClip.loop();
  237.             return;
  238.          }
  239.  
  240.          if (this.autoPlay) {
  241.             this.theAudioClip.play();
  242.          }
  243.       }
  244.  
  245.    }
  246.  
  247.    public void Stop() {
  248.       if (this.theAudioClip != null) {
  249.          this.theAudioClip.stop();
  250.       }
  251.  
  252.    }
  253. }
  254.